package commons;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

public class jdbcUtils {
    private static String username;
    private static String userpwd;
    private static String url;
    private static String driver;
    static {


        try {
            ResourceBundle bundle = ResourceBundle.getBundle("druid");
            username = bundle.getString("username");
            userpwd = bundle.getString("password");
            url=bundle.getString("url");
            driver=bundle.getString("driver");
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static  Connection getConnection(){
        Connection conn=null;
        try {
           conn= DriverManager.getConnection(url,username,userpwd);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return conn;
    }
    public static void closeConnection(Connection conn) {
        try {
            conn.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
